<?php
require_once './database/connection.php';
require_once './database/articles.php';
require_once './database/modify.php';
require_once './database/categories.php';
$obj = new articles();
    $data = $obj->view_all();
    $mod = new modify_data();
   $ds = new categories();
   $cate = $ds->laydanhsach();
?>
<div id="content">
    
        <div class="post">
            <form action="content_5.php" method="post"> 
            <table>
                <tr>
                    <td>id: </td>
                    <td><select name="id_update">
                                    <?php foreach ($data as $data1){ 
                                        echo '<option value="'.$data1['id'].'">'.$data1['id'].'</option>';
                                    }
?>
                                    
                        </select></td>
                </tr>
                <tr>
                    <td>title: </td>
                    <td><input type="text" name="title_update"></td>
                </tr>
                <tr>
                    <td>overview: </td>
                    <td><input type="text" name="overview_update"></td>
                </tr>
                <tr>
                    <td>body: </td>
                    <td><input type="text" name="body_update"></td>
                </tr>
                <tr>
                    <td>id_category: </td>
                    <td><select name="id_category_update">
                                    <?php foreach ($cate as $data2){ 
                                        echo '<option value="'.$data2['id'].'">'.$data2['name'].'</option>';
                                    }
?>
                        </select></td>
                </tr>
                <tr>
                    <td> </td>
                    <td><input type="submit" name="ok" value="update"></td>
                </tr>
            </table>
                <table>
                    <tr>
                        <td>id</td>
                        <td>title</td>
                        <td>overview</td>
                        <td>id_category</td>
                    </tr>
                    <?php
                    foreach ($data as $dulieu){
                        echo "<tr><td>".$dulieu['id']."</td><td>".$dulieu['title']."</td><td>".$dulieu['overview']."</td><td>".$dulieu['id_category']."</td>";
                    }
                    ?>
                </table>
            </form>
            </div>
<?php 
    if(isset($_POST['ok'])){
        $mod->capnhat_data();
        header("location: index.php");
    }
?>

